package gw.com.android.ui.positions;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.gwtsz.gts2.hx.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import gw.com.android.app.ActivityManager;
import gw.com.android.app.AppMain;
import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigTypesDeal;
import gw.com.android.ui.SimpleItemAdapter;
import gw.com.android.utils.MobclickEventUtlis;
import gw.com.android.utils.PackStatis;
import www.com.library.app.Logger;
import www.com.library.app.PushMsgTabFragment;
import www.com.library.model.DataItemDetail;
import www.com.library.model.DataItemResult;
import www.com.library.view.RecycleViewDivider;
import www.com.library.view.RecyclerClickListener;

/**
 * 更多界面
 */
public class MoreFragment extends PushMsgTabFragment {

    /**
     * 更多列表控件
     **/
    @BindView(R.id.list_view)
    protected RecyclerView mListView;

    private DataItemResult mItemData = null;
    private SimpleItemAdapter mAdapter;
    private ConfigTypesDeal mTypeDeal;

    public MoreFragment() {
        // Required empty public constructor
    }

    public static MoreFragment newInstance() {
        MoreFragment fragment = new MoreFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {

        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main_trade_more;
    }

    @Override
    protected void initLayoutView() {
        ButterKnife.bind(this, mRootView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        mListView.setLayoutManager(linearLayoutManager);
        mListView.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.VERTICAL));
    }

    @Override
    protected void initViewData() {
        mTypeDeal = new ConfigTypesDeal();
        mItemData = mTypeDeal.getMoreTypeList();
        mAdapter = new SimpleItemAdapter(getActivity(), mItemData, new RecyclerClickListener() {
            @Override
            public void onClick(int position, DataItemDetail itemDetail) {
                String key = mAdapter.getKey(position);
                if (null == key || key.length() < 1) {
                    return;
                }
                DataItemDetail mItem = mItemData.getItem(position);
                mItem.setStringValue(ConfigType.CONFIG_TYPE_KEY_TAG, ConfigType.REPORT_TAG);
                Logger.e("MoreFragment key = " + mItem.getString(ConfigType.CONFIG_TYPE_KEY_TAG));
                String value = mItem.getString(ConfigType.CONFIG_TYPE_VALUE_TAG);
                if ("tradeRecord".equals(value)) {
                    PackStatis.getToService("ClickTradeReport1", "RiskControl", null, null);
                } else if ("entrustRecord".equals(value)) {
                    PackStatis.getToService("ClickTradeReport2", "RiskControl", null, null);
                } else if ("profitAndLossRecord".equals(value)) {
                    PackStatis.getToService("ClickTradeReport3", "RiskControl", null, null);
                } else if ("creditRecord".equals(value)) {
                    PackStatis.getToService("ClickTradeReport4", "RiskControl", null, null);
                }
                ActivityManager.showWebPageActivity(getActivity(), mItem, AppMain.getAppString(R.string.main_menu_item_trade));
                MobclickEventUtlis.MobclickEventByAccountType(getActivity(), "PositionMore" + position);
            }
        });
        mListView.setAdapter(mAdapter);
    }
}
